php 8 major changes - Nullsafe operator

94

php 8 major changes - Nullsafe operator -

BEFORE
$country =  null;

if ($session !== null) {
  $user = $session->user;

  if ($user !== null) {
    $address = $user->getAddress();
 
    if ($address !== null) {
      $country = $address->country;
    }
  }
}
AFTER
$country = $session?->user?->getAddress()?->country;

Comments

Submit
0 Comments